package com.zyf.mapreduce.writable;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Job;
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;

import java.io.IOException;

/**
 * @author Malegod_xiaofei
 * @create 2024-07-21-20:21
 */
public class FlowDriver {
    public static void main(String[] args) throws IOException, ClassNotFoundException, InterruptedException {

        // 1 获取 job
        Configuration conf = new Configuration();
        Job job = Job.getInstance(conf);

        // 2 设置 jar
        job.setJarByClass(FlowDriver.class);

        // 3 关联 Mapper Reducer
        job.setMapperClass(FlowMapper.class);
        job.setReducerClass(FlowReducer.class);

        // 4 设置 Mapper 输出的 key 和 value 类型
        job.setMapOutputKeyClass(Text.class);
        job.setMapOutputValueClass(FlowBean.class);

        // 5 设置最终数据输出的 key 和 value 类型
        job.setOutputKeyClass(Text.class);
        job.setOutputValueClass(FlowBean.class);

        // 6 设置数据的输入路径和输出路径
        /*FileInputFormat.setInputPaths(job, new Path("E:\\Data\\尚硅谷\\尚硅谷大数据学科全套教程\\2.尚硅谷大数据学科--核心框架\\尚硅谷大数据技术之Hadoop3.x\\资料\\11_input\\inputflow"));
        FileOutputFormat.setOutputPath(job, new Path("E:\\Output\\MapReduce\\Flow"));*/
        FileInputFormat.setInputPaths(job, new Path(args[0]));
        FileOutputFormat.setOutputPath(job, new Path(args[1]));

        // 7 提交 job
        boolean result = job.waitForCompletion(true);
        System.exit(result ? 0 : 1);
    }
}
